﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace _180FrameWork.DataBaseHelper
{
    public interface IDbHelper
    {
        #region SQL
        /// <summary>
        /// 执行sql返回实体列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql"></param>
        /// <returns></returns>
        IList<T> ExecuteSql<T>(string strSql) where T : new();

        /// <summary>
        /// 执行sql返回实体列表（带参数）
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql"></param>
        /// <returns></returns>
        IList<T> ExecuteSql<T>(string strSql, IDictionary<string, object> paramValues) where T : new();

        /// <summary>
        /// 执行SQL语句，返回数据集
        /// </summary>
        /// <param name="strSql"></param>
        /// <returns></returns>
        DataSet ExecuteSql(string strSql);
        /// <summary>
        ///  执行SQL语句，返回数据集（带参数）
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        DataSet ExecuteSql(string strSql, IDictionary<string, object> paramValues);
        /// <summary>
        /// 执行SQL语句，返回受影响的行数
        /// </summary>
        /// <param name="strSql"></param>
        /// <returns></returns>
        int ExecuteNoQuerySql(string strSql);
        /// <summary>
        /// 执行SQL语句，返回受影响的行数（带参数）
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        int ExecuteNoQuerySql(string strSql, IDictionary<string, object> paramValues);
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="strSql"></param>
        /// <returns></returns>
        bool Exists(string strSql);
        /// <summary>
        /// 是否存在（带参数）
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        bool Exists(string strSql, IDictionary<string, object> paramValues);
        #endregion

        #region 存储过程
        /// <summary>
        /// 执行sql返回实体列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql"></param>
        /// <returns></returns>
        IList<T> ExecuteSp<T>(string strSql) where T : new();

        /// <summary>
        /// 执行sql返回实体列表（带参数）
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql"></param>
        /// <returns></returns>
        IList<T> ExecuteSp<T>(string strSql, IDictionary<string, object> paramValues) where T : new();
        /// <summary>
        /// 执行存储过程，返回数据集
        /// </summary>
        /// <param name="strSpName"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        DataSet ExecuteSp(string strSpName, object[] paramValues);
        /// <summary>
        /// 执行存储过程，返回受影响的行数
        /// </summary>
        /// <param name="strSpName"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        int ExecuteNoQuerySp(string strSpName, object[] paramValues);
        /// <summary>
        /// 执行存储过程，返回特定参数值
        /// </summary>
        /// <param name="strSpName"></param>
        /// <param name="paramValues"></param>
        /// <param name="returnParamNames"></param>
        /// <returns></returns>
        object[] ExecuteParamSp(string strSpName, object[] paramValues, string[] returnParamNames);
        #endregion

        #region 事务
        /// <summary>
        /// 开始事务
        /// </summary>
        void BeginTran();
        /// <summary>
        /// 提交事务
        /// </summary>
        void Commit();
        /// <summary>
        /// 回滚事务
        /// </summary>
        void Rollback();
        #endregion

        #region 命令
        /// <summary>
        /// 执行命令，返回受影响的行数
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        int ExecuteNoQueryCmd(DbCommand command);

        #endregion
    }
}
